package com.itboye.ihomebank;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.bumptech.glide.Glide;
import com.itboye.ihomebank.activity.electric_meter.ActivityHouseAddress;
import com.itboye.ihomebank.activity.electric_meter.ActivitySmartMeter;
import com.itboye.ihomebank.activity.electric_meter.IntroduceElecMeter;
import com.itboye.ihomebank.activity.finance.MonthPayActivity;
import com.itboye.ihomebank.activity.home.ActivityFaBuHouse;
import com.itboye.ihomebank.activity.home.ActivityHomeSouSuo;
import com.itboye.ihomebank.activity.home.ActivityHotSouSuo;
import com.itboye.ihomebank.activity.homefragment.HouseDetailActivity;
import com.itboye.ihomebank.activity.login.LoginActivity;
import com.itboye.ihomebank.activity.me.ActivityMyData;
import com.itboye.ihomebank.activity.myzhujia.ActivityRepair;
import com.itboye.ihomebank.adapter.HomeAdapter;
import com.itboye.ihomebank.base.BaseFragment;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.base.ptr.BasePtr;
import com.itboye.ihomebank.bean.ElectricMeterBean;
import com.itboye.ihomebank.bean.HouseBean;
import com.itboye.ihomebank.bean.HouseListBean;
import com.itboye.ihomebank.bean.LunBoBean;
import com.itboye.ihomebank.bean.MeterDetailBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.bean.UpdateVersionBean;
import com.itboye.ihomebank.constants.NetPublicConstant;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.custom.CarouselView;
import com.itboye.ihomebank.custom.MyListView;
import com.itboye.ihomebank.presenter.ElectricMeterPresenter;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.presenter.UpdatePresenter;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.PtrHTFrameLayout;
import com.itboye.ihomebank.util.SPUtils;
import com.itboye.ihomebank.util.UpdateManager;
import com.itboye.ihomebank.util.controller.LoginController;
import com.itboye.ihomebank.web.LunBoWebActivity;
import com.itboye.ihomebank.web.WebActivity;
import com.itboye.ihomebank.widget.BatteryView;
import com.itboye.ihomebank.widget.choosecity.CityListActivity;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.LoopPagerAdapter;
import com.jude.rollviewpager.hintview.IconHintView;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import in.srain.cube.views.ptr.PtrDefaultHandler2;
import in.srain.cube.views.ptr.PtrFrameLayout;

/**
 * 首页
 */
public class HomeFragment extends BaseFragment implements OnClickListener,
        Observer {

    private CarouselView banner_top;
    private MyListView home_listview;
//    TextView home_et_sousuo;
    private ArrayList<HouseBean> arrayListHouse = new ArrayList<HouseBean>();
    HousePresenter housePresenter;

    // 智能门锁，签约，预约，求租
    LinearLayout include_01, include_02, include_03, include_04;
    // 维修服务，一键缴费，家政服务，签证旅游
    RelativeLayout include_weixiu, include_jiaofei, include_jiazheng,
            include_qianzheng;
    PtrHTFrameLayout commend_anchor_ptr;
    private HomeAdapter adapter;
    protected String city;
    protected double lat;
    protected double lng;
    protected float radius;
    protected boolean isFirstLoc = true;
    RollPagerView lunbo;
    private int pageNo = 1;
    String versionNow;
    UpdatePresenter updatePresenter;
    ElectricMeterPresenter electricMeterPresenter;
    ImageView table_mess_img;
    private float lastX;
    private float lastY;
    private ScrollView home_scrollView;
    private float pressY;
    private float pressX;
    private String broker_validate;
    //title
    RelativeLayout home_city,home_city1;// 切换城市
    RelativeLayout home_sousuo,home_sousuo1;// 搜索
    TextView tvcity,tvcity1;

    View v_statusbar,v_statusbar1;
    RelativeLayout relyoutcitys,relyoutcitys1; //title 背景色

    //电表属性
    RelativeLayout batteryRl; //电表电量
    BatteryView batteryView; //自定义的电池
    TextView elecMeterTv;
    TextView batterySum;  //电量
    List<ElectricMeterBean> meterBeans;
    LinearLayout textView1;

    @Override
    public int initView() {
        return R.layout.fragment_home;
    }

    private String uid;
    private UserPresenter userPresenter;

    public LocationClient mLocationClient = null;
    public BDLocationListener myListener = new MyLocationListener();
    //登录和退出登录的广播
    BroadcastReceiver loginReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            Log.e("Home----","true");
            uid = SPUtils.get(getActivity(), null, SPContants.USER_ID, "") + "";
            initBattery();
            isShowRedDot();
        };
    };


    @Override
    public void onMyActivityCreated() {
//        if (MainActivity.isLock){
            setStatusBarHeight(v_statusbar);
            setStatusBarHeight(v_statusbar1);
//        }else {
//
//        }

        //退出登录发送过来的广播
        IntentFilter filter1 = new IntentFilter(ActivityMyData.AVARTACTION);
        getActivity().registerReceiver(loginReceiver, filter1);
        //登录的广播
        IntentFilter filter2 = new IntentFilter("changeByMainActivity");
        getActivity().registerReceiver(loginReceiver, filter2);

        broker_validate= SPUtils.get(getActivity(),null,SPContants.BrokerValidate,"")+"";
        isShowRedDot();
        mLocationClient = new LocationClient(getActivity()); // 声明LocationClient类
        mLocationClient.registerLocationListener(myListener); // 注册监听函数
        setLocationOption();
        showProgressDialog("数据加载中,请稍后", true);
        versionNow = getAppVersionName(getActivity());
        userPresenter = new UserPresenter(this);
        electricMeterPresenter=new ElectricMeterPresenter(this);
        housePresenter = new HousePresenter(this);
        updatePresenter = new UpdatePresenter(this);

        BasePtr.setPagedPtrStyle(commend_anchor_ptr);
        commend_anchor_ptr.autoRefresh(true);
        commend_anchor_ptr.setViewPager(lunbo);
        commend_anchor_ptr.setPtrHandler(new PtrDefaultHandler2() {
            @Override
            public void onLoadMoreBegin(PtrFrameLayout frame) {
                uid = SPUtils.get(getActivity(), null, SPContants.USER_ID, "") + "";
                pageNo++;
                housePresenter.queryHouse("330100", "", "", "", "", "", "", "", "", "",
                        "", "", "", "10", pageNo + "", uid);

            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                uid = SPUtils.get(getActivity(), null, SPContants.USER_ID, "") + "";
                pageNo = 1;
//                userPresenter.lunbo("6045");
                housePresenter.queryHouse("330100", "", "", "", "", "", "", "", "", "",
                        "", "", "", "10", pageNo + "", uid);
                //获取列表
                initBattery();
            }
        });


        userPresenter.lunbo("6045");
        uid = SPUtils.get(getActivity(), null, SPContants.USER_ID, "") + "";
        meterBeans=new ArrayList<>();

        housePresenter.queryHouse("330100", "", "", "", "", "", "", "", "", "",
                "", "", "", "10", "", uid);
        home_listview = (MyListView) getView().findViewById(R.id.mylistview);
        adapter = new HomeAdapter(getActivity(),
                list);
        home_listview.setAdapter(adapter);
        home_listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(getActivity(),
                        HouseDetailActivity.class);
                intent.putExtra("lng", lng);
                intent.putExtra("lat", lat);
                intent.putExtra("radius", radius);
                intent.putExtra("house_no",
                        list.get(position).getHouseNo());
                startActivity(intent);
            }
        });
        //初始化智能电表
        initBattery();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            home_scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
                @Override
                public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                Log.d("=====fragment",scrollY+"");
                if (scrollY>0){
                    relyoutcitys.setVisibility(View.GONE);
                    v_statusbar.setVisibility(View.GONE);
                    v_statusbar1.setVisibility(View.VISIBLE);
                    relyoutcitys1.setVisibility(View.VISIBLE);
                    if (scrollY>40){
                        relyoutcitys1.setBackgroundColor(getActivity().getResources().getColor(R.color.title_blue));
                        setStatusBarColor(v_statusbar1,getActivity().getResources().getColor(R.color.title_blue));
                    }else {
                        relyoutcitys1.setBackgroundColor(Color.TRANSPARENT);
                        setStatusBarColor(v_statusbar1,Color.TRANSPARENT);
                    }
                }else {
                    relyoutcitys.setVisibility(View.VISIBLE);
                    v_statusbar.setVisibility(View.VISIBLE);
                    v_statusbar1.setVisibility(View.GONE);
                    relyoutcitys1.setVisibility(View.GONE);
                }

                }
            });
        }else {
            relyoutcitys.setBackgroundColor(getActivity().getResources().getColor(R.color.title_blue));
        }


        //设置title背景色和alpha



    }

    private void initBattery() {
        if (uid.equals("")){
            batteryRl.setVisibility(View.INVISIBLE);
            elecMeterTv.setText("掌上用电助手");
        }else {
            electricMeterPresenter.queryMyEmeter(uid,"","");
        }
    }


    public void isShowRedDot(){
        //接受附件单红点消息
        boolean fuJianOrder = (boolean) SPUtils.get(getActivity(),null,SPContants.FUJIAN_ORDER,false);
        if (fuJianOrder){ //我的签约的红点
//                home_img.setVisibility(View.VISIBLE);
            table_mess_img.setVisibility(View.VISIBLE);
//                wode_img.setVisibility(View.VISIBLE);
        }else {
//                home_img.setVisibility(View.GONE);
            table_mess_img.setVisibility(View.GONE);
//                wode_img.setVisibility(View.GONE);
        }

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }

    @Override
    public void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
       // setLocationOption();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        try {
            mLocationClient.stop();// 停止定位
        }catch (Exception e){
        }
        getActivity().unregisterReceiver(loginReceiver);
    }

    public void onClick(View arg0) {
        Intent intent = null;
        switch (arg0.getId()) {
            case R.id.home_city:// 切换城市
            case R.id.home_city1:
                intent = new Intent(MyApplcation.ctx, CityListActivity.class);
                startActivity(intent);
                break;

            case R.id.home_sousuo1:// 搜索
            case R.id.home_sousuo:// 搜索
                intent = new Intent(MyApplcation.ctx, ActivityHotSouSuo.class);
                intent.putExtra("content", "");
                startActivity(intent);
                break;
            case R.id.include_01:// 发布
                uid = SPUtils.get(getActivity(), null, SPContants.USER_ID, "") + "";
                if (uid.equals("")) {
                    intent = new Intent(getActivity(), LoginActivity.class);
                    startActivity(intent);
                } else {
                    if (SPUtils.get(getActivity(), null,
                            SPContants.IdentityValidate, "").equals("0")) {
                        ByAlert.alert("请先实名制");
                    } else if (SPUtils.get(getActivity(), null,
                            SPContants.IdentityValidate, "").equals("2")) {
                        ByAlert.alert("实名制审核中");
                    } else {
                        intent = new Intent(MyApplcation.ctx,
                                ActivityFaBuHouse.class);
                        startActivity(intent);
                    }
                }
                break;
            case R.id.include_02:// 我的预约
                uid = SPUtils.get(getActivity(), null, SPContants.USER_ID, "") + "";
                if (uid.equals("")) {
                    intent = new Intent(getActivity(), LoginActivity.class);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), ActivityHomeSouSuo.class);
                    startActivity(intent);
                }
                break;
            case R.id.include_03:// 我的签约
                LoginController.onMySignClick(getActivity(), null);
                break;
            case R.id.include_04:// 收藏
                LoginController.onMyCollectionClick(getActivity(), null);
                break;
            case R.id.include_weixiu:// 住家维修
                uid = SPUtils.get(getActivity(), null, SPContants.USER_ID, "") + "";
                if (uid.equals("")) {
                    intent = new Intent(getActivity(), LoginActivity.class);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), ActivityRepair.class);
                    startActivity(intent);
                }
                break;
            case R.id.include_jiaofei:   // 电表
            case R.id.include_im_02:
            case R.id.elecMeterTv:
            case R.id.batteryView:
//                ByAlert.alert("待开发...");
                if (uid.equals("")) {
                    intent = new Intent(getActivity(), LoginActivity.class);
                    startActivity(intent);
                } else {
                    if (elecMeterTv.getText().toString().trim().equals("掌上用电助手")){
                        //介绍电表
                        startActivity(new Intent(getActivity(), IntroduceElecMeter.class));
                    }else {
                        //电表界面
                        if (meterBeans.size()>1||meterBeans.get(0).getEmeter_list().size()>1){
                            startActivity(new Intent(getActivity(), ActivityHouseAddress.class));
                        }else {
                            Intent intent1 = new Intent(getActivity(), ActivitySmartMeter.class);
                            intent1.putExtra("position",0);
                            intent1.putExtra("xiaoqu_id",meterBeans.get(0).getId());
                            MeterDetailBean meterDetailBean = meterBeans.get(0).getEmeter_list().get(0);
                            meterDetailBean.setAddress(meterBeans.get(0).getAddress()+"_"+meterBeans.get(0).getEmeter_list().get(0).getName());
                            intent1.putExtra("meter_detail",meterDetailBean);
                            startActivity(intent1);
                        }
                    }
                }

                break;
            case R.id.include_jiazheng:// 住家月付
                uid = SPUtils.get(getActivity(), null, SPContants.USER_ID, "") + "";
                if (uid.equals("")) {
                    intent = new Intent(getActivity(), LoginActivity.class);
                    startActivity(intent);
                } else {
                    intent=new Intent(getActivity(), MonthPayActivity.class);
//                    intent = new Intent(getActivity(), FinanceActivity.class);
                    startActivity(intent);
                }

                break;
            case R.id.include_qianzheng:// 积分商城
//                ByAlert.alert("待开发");
//
                uid = SPUtils.get(getActivity(), null, SPContants.USER_ID, "") + "";
                if (uid.equals("")) {
                    intent = new Intent(getActivity(), LoginActivity.class);
                    startActivity(intent);
                } else {
                    intent = new Intent(getActivity(), WebActivity.class);
//                    intent.putExtra("url", NetPublicConstant.WEB_URL02+"/vip/travel");
//                intent.putExtra("url", "http://hzzhongrui.travel.bbcmart.com/");
                    intent.putExtra("url", "http://apitest.91renta.com/public/index.php/estore/pay?params=IiIU%2BWiCyOS6Ge4fiI1Hh2142%2FhCgdhp%2FM70%2FVqNuV4pz0RfNvuI%2FuSi8674Qt9u");
                    intent.putExtra("title", "积分商城");
                    startActivity(intent);
                }
//                intent = new Intent(getActivity(), ActivityExchangeMall.class);
//                startActivity(intent);
                break;

            default:
                break;
        }
    }

    private HouseListBean houseListBean;
    private RelativeLayout one;
    List<HouseListBean.HouseItem> list = new ArrayList<>();

    @Override
    public void update(Observable observable, Object data) {
        // TODO Auto-generated method stub
        ResultEntity entity = handlerError(data);
        try {
            closeProgressDialog();
        } catch (Exception e) {

        }
        if (entity != null) {

            if (entity.getEventType() == HousePresenter.queryHouse_success) {
                houseListBean = (HouseListBean) entity.getData();
                if (houseListBean == null) {
                    // no_data.setVisibility(View.VISIBLE);
                    // sousuo_listview.setVisibility(View.GONE);
                    ByAlert.alert("没有数据了");
                    commend_anchor_ptr.refreshComplete();
                    return;

                }
                if (houseListBean.getData().size() <= 0) {
                    ByAlert.alert("没有数据了");
                    commend_anchor_ptr.refreshComplete();
                    // no_data.setVisibility(View.VISIBLE);
                    // sousuo_listview.setVisibility(View.GONE);
                    return;
                }
                // no_data.setVisibility(View.GONE);
                // sousuo_listview.setVisibility(View.VISIBLE);
                if (pageNo == 1) {
                    list.clear();
                }
                list.addAll(houseListBean.getData());
                adapter.notifyDataSetChanged();

            } else if (entity.getEventType() == HousePresenter.queryHouse_fail){
                if (!uid.equals("")){
                    ByAlert.alert(entity.getMsg());
                }
            } else if (entity.getEventType() == UserPresenter.lunbo_success) {
                List<LunBoBean> LunboBean = (List<LunBoBean>) entity.getData();
                //新的
//                ArrayList<String> imgs = new ArrayList<>();
//                for (int i=0;i<LunboBean.size();i++){
//                    imgs.add(NetPublicConstant.IMAGE_URL+LunboBean.get(i).getImg());
//                }

                lunbo.setPlayDelay(3000);
                TestLoopAdapter testLoopAdapter = new TestLoopAdapter(lunbo);
                testLoopAdapter.setImgs(LunboBean);
                lunbo.setAdapter(testLoopAdapter);
                lunbo.setHintView(new IconHintView(getActivity(),R.drawable.lunbo_check,R.drawable.lunbo_uncheck,28));

//                //  旧的轮播
//                ArrayList<ImageView> arrayBmps = new ArrayList<>();
//                for (int i = 0; i < LunboBean.size();i++) {
//                    LoweImageView imageView = new LoweImageView(getActivity());
//                    imageView.setScaleType(ScaleType.FIT_XY);
//                    try {
//                        XImageLoader.load(NetPublicConstant.IMAGE_URL
//                                + LunboBean.get(i).getImg(), imageView);
//                    }catch (Exception e){
//
//                    }
//                    arrayBmps.add(imageView);
//                    imageView.setTag(i);
//
//
//                    final String url=LunboBean.get(i).getUrl();
//                    final String title=LunboBean.get(i).getTitle();
//                    if (!url.equals("")){
//                        imageView.setOnClickListener(new OnClickListener() {
//                            @Override
//                            public void onClick(View v) {
//                                Intent  intent = new Intent(getActivity(), WebActivity.class);
//                                intent.putExtra("url", url);
//                                intent.putExtra("title", title);
//                                startActivity(intent);
////                                Uri uri = Uri.parse("http://dx.bankbaoxian.com/shortX/#/shortXZJ");
////                                startActivity(new Intent(Intent.ACTION_VIEW,uri));
//                            }
//                        });
//                    }
//                }
//                lunbo.setImageBitmaps(arrayBmps);

            } else if (entity.getEventType() == UserPresenter.lunbo_fail) {
                if (!uid.equals("")){
                    ByAlert.alert(entity.getMsg());
                }
            }else  if (entity.getEventType() == ElectricMeterPresenter.BY_Emeter_address_success){ //我的电表列表
                meterBeans= (List<ElectricMeterBean>) entity.getData();
               List<MeterDetailBean>  meters=new ArrayList<>();

                for (int i=0;i<meterBeans.size();i++){
                    for (int j=0;j<meterBeans.get(i).getEmeter_list().size();j++){
                        meters.addAll(meterBeans.get(i).getEmeter_list());
                    }
                }
                Log.d("====emeter",meterBeans.toString());
                  if (meters.size()>0){ //有签订房源并的绑定电表列表
                      batteryRl.setVisibility(View.VISIBLE);
                      elecMeterTv.setText("电量");
                      if (Double.parseDouble(meterBeans.get(0).getEmeter_list().get(0).getValue_remain())<0){
                          batteryView.setPower(0);
                      }else
                      if (Double.parseDouble(meterBeans.get(0).getEmeter_list().get(0).getValue_remain())<1){ //进位取整
                          int ceil = (int) Math.ceil(Double.parseDouble(meterBeans.get(0).getEmeter_list().get(0).getValue_remain()));
                          batteryView.setPower(ceil);
                          Log.d("====emeter",ceil+"");
                      }else { //去掉小数取整
                          int floor = (int) Math.floor(Double.parseDouble(meterBeans.get(0).getEmeter_list().get(0).getValue_remain()));
                          batteryView.setPower(floor);
                          Log.d("====emeter",floor+"");
                      }
                      if (Double.parseDouble(meterBeans.get(0).getEmeter_list().get(0).getValue_remain())<20){ //变红
                          batteryView.setColor(Color.RED);
                          batterySum.setTextColor(getActivity().getResources().getColor(R.color.text_black));
                      }
//                      else if (Double.parseDouble(meterBeans.get(0).getEmeter_list().get(0).getValue_remain())<50){ // BLUE
//                          batteryView.setColor(Color.BLUE);
//                          batterySum.setTextColor(Color.BLUE);
//                      }
                      else { //homegreen
                          batteryView.setColor(getActivity().getResources().getColor(R.color.homegreen));
                          batterySum.setTextColor(getActivity().getResources().getColor(R.color.text_black));
                      }
                      int floor = (int) Math.floor(Double.parseDouble(meterBeans.get(0).getEmeter_list().get(0).getValue_remain()));
                      batterySum.setText(floor+"");
                  }else { //无电表 跳转介绍电表界面

                      batteryRl.setVisibility(View.INVISIBLE);
                      elecMeterTv.setText("掌上用电助手");
                  }

            }else  if (entity.getEventType() == ElectricMeterPresenter.BY_Emeter_address_fail){
                if(!uid.equals("")){
                    ByAlert.alert(entity.getMsg());
                }
            }
            one.setFocusable(true);
            one.setFocusableInTouchMode(true);
            one.requestFocus();
            // home_scrollView.smoothScrollTo(0, 0);

        }
        commend_anchor_ptr.refreshComplete();

    }



    /**
     * 设置相关参数
     */
    private void setLocationOption() {
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true);
        // option.setIsNeedAddress(true); // 返回的定位结果包含地址信息
        option.setAddrType("all"); // 返回的定位结果包含地址信息
        option.setCoorType("bd09ll"); // 返回的定位结果是百度经纬度,默认值gcj02
        option.setScanSpan(5000); // 设置发起定位请求的间隔时间为5000ms
        option.disableCache(true); // 禁止启用缓存定位
        option.setPoiNumber(5); // 最多返回POI个数
        option.setPoiDistance(1000); // poi查询距离
        option.setPoiExtraInfo(true); // 是否需要POI的电话和地址等详细信息
        mLocationClient.setLocOption(option);
        mLocationClient.start();// 开始定位
    }

    public class MyLocationListener implements BDLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location) {
            if (location == null)
                return;
            StringBuffer sb = new StringBuffer(256);
            sb.append("time : ");
            sb.append(location.getTime());
            sb.append("\nerror code : ");
            sb.append(location.getLocType());
            sb.append("\nlatitude : ");
            sb.append(location.getLatitude());
            sb.append("\nlontitude : ");
            sb.append(location.getLongitude());
            sb.append("\nradius : ");
            sb.append(location.getRadius());
            if (location.getLocType() == BDLocation.TypeGpsLocation) {
                sb.append("\nspeed : ");
                sb.append(location.getSpeed());
                sb.append("\nsatellite : ");
                sb.append(location.getSatelliteNumber());
            } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
                sb.append("\naddr : ");
                sb.append(location.getAddrStr());
            }
            lat = location.getLatitude();
            lng = location.getLongitude();
            radius = location.getRadius();
            city = location.getCity();
            SPUtils.put(getActivity(), null, SPContants.SELECT_CITY,
                    city == null ? "杭州市" : city);

            if (city==null){
                tvcity.setText("杭州市");
                tvcity1.setText("杭州市");
            }else{
                tvcity.setText(location.getCity());
                tvcity1.setText(location.getCity());
            }

           // tvcity.setText(location.getCity() + location.getDistrict());
         //   dingwei.setText(sb.toString());
        }

        public void onReceivePoi(BDLocation poiLocation) {

        }
    }
    //轮播adapter
    private class TestLoopAdapter extends LoopPagerAdapter {
        List<LunBoBean> urlList ;

        public void setImgs( List<LunBoBean> Lunbo ){
            this.urlList = Lunbo;
            notifyDataSetChanged();
        }


        public TestLoopAdapter(RollPagerView viewPager) {
            super(viewPager);
        }

        @Override
        public View getView(ViewGroup container, final int position) {
            Log.i("RollViewPager","getView:"+NetPublicConstant.IMAGE_URL+urlList.get(position).getImg());

            ImageView view = new ImageView(container.getContext());
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.i("RollViewPager","onClick");
                }
            });
            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
            view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            Glide.with(getActivity())
                    .load(NetPublicConstant.IMAGE_URL+urlList.get(position).getImg())
                    .into(view);
            view.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!"".equals(urlList.get(position).getUrl())){
                        Intent intent = new Intent(getActivity(), LunBoWebActivity.class);
                        intent.putExtra("url",urlList.get(position).getUrl());
                        startActivity(intent);
                    }
                }
            });
            return view;
        }

        @Override
        public int getRealCount() {
            return urlList.size();
        }

    }


}
